'use strict';

const Service = require('egg').Service;

class ScoreService extends Service {
    //
    async select(time,num) {
        return await this.app.mysql.query('select * from scorelist where timer=? and num=?',[time,num])
    }
    async add(username,skill,theory,num,time){
        await this.app.mysql.query('insert into scorelist (username,skill,theory,num,timer) values (?,?,?,?,?)',[username,skill,theory,num,time])
    }
    async update(skill,theory,id){
        await this.app.mysql.query('update scorelist set skill=?,theory=? where id=?',[skill,theory,id])
    }
    async del(id){
        await this.app.mysql.query('delete from scorelist where id=?',[id])
    }
    //查询今天的录入成绩的列表
    async index(timer){
        return await this.app.mysql.query('select * from scorelist where timer=?',[timer]);
    }
    //获取今天没有录入成绩的人员名单
    async notScore(timer){
        return await this.app.mysql.query('select u.username,u.num from userlist u where num not in (select s.num from scorelist s where timer=?) and role_id!=1',[timer])
    }
    //搜索
    async search(searchKey,timer){
        return await this.app.mysql.query(`select * from scorelist where timer=? and username like '%${searchKey}%'`,[timer]);
    }
}

module.exports = ScoreService;
